package com.warski.wonderfires.dlna.listener;

import com.warski.wonderfires.utils.Logger;
import org.fourthline.cling.model.meta.LocalDevice;
import org.fourthline.cling.model.meta.RemoteDevice;
import org.fourthline.cling.registry.Registry;
import org.fourthline.cling.registry.RegistryListener;

/**
 * Created by xuhaiping on 2020/9/2.
 */
public class DLNARegistryListener implements RegistryListener {
    private DLNADeviceListener deviceListener = null;

    public DLNADeviceListener getDeviceListener() {
        return deviceListener;
    }

    public void setDeviceListener(DLNADeviceListener deviceListener) {
        this.deviceListener = deviceListener;
    }

    public DLNARegistryListener() {

    }

    @Override
    public void remoteDeviceDiscoveryStarted(Registry registry, RemoteDevice device) {
        Logger.info("RemoteDeviceDiscoveryStarted");
    }

    @Override
    public void remoteDeviceDiscoveryFailed(Registry registry, RemoteDevice device, Exception ex) {
        Logger.info("RemoteDeviceDiscoveryFailed");
    }

    @Override
    public void remoteDeviceAdded(Registry registry, RemoteDevice device) {
        Logger.info("RemoteDeviceAdded");
        if (deviceListener != null) {
            deviceListener.onDeviceListRefresh(registry.getDevices());
        }
    }

    @Override
    public void remoteDeviceUpdated(Registry registry, RemoteDevice device) {
        Logger.info("RemoteDeviceUpdated");
    }

    @Override
    public void remoteDeviceRemoved(Registry registry, RemoteDevice device) {
        Logger.info("RemoteDeviceUpdated");
        if (deviceListener != null) {
            deviceListener.onDeviceListRefresh(registry.getDevices());
        }
    }

    @Override
    public void localDeviceAdded(Registry registry, LocalDevice device) {
        Logger.info("LocalDeviceAdded");
        if (deviceListener != null) {
            deviceListener.onDeviceListRefresh(registry.getDevices());
        }
    }

    @Override
    public void localDeviceRemoved(Registry registry, LocalDevice device) {
        Logger.info("LocalDeviceRemoved");
        if (deviceListener != null) {
            deviceListener.onDeviceListRefresh(registry.getDevices());
        }
    }

    @Override
    public void beforeShutdown(Registry registry) {
        Logger.info("BeforeShutdown");
    }

    @Override
    public void afterShutdown() {
        Logger.info("AfterShutdown");
    }
}
